import 'package:extended_image/extended_image.dart';
import 'package:flutter/material.dart';
import 'package:flutterlib/common/config/config.dart';
import 'package:flutterlib/common/style/font_awesome4_icons.dart';
import 'package:flutterlib/common/style/meterial_design_icons.dart';
import 'package:flutterlib/common/style/quhui_style.dart';
import 'package:flutterlib/common/utils/navigator_utils.dart';
import 'package:flutterlib/model/post/post_bean.dart';
import 'package:flutterlib/widgets/bussiness/user_info_widget.dart';
import 'package:like_button/like_button.dart';

class PostListItemAdmin extends StatelessWidget {
  final PostBean postBean;

  final VoidCallback onPressed;
  final VoidCallback onPassPressed;
  final VoidCallback onRejectPressed;
  final AnimationController animationController;
  final Animation<dynamic> animation;

  PostListItemAdmin(this.postBean,
      {this.onPressed,
      this.animationController,
      this.animation,
      this.onPassPressed,
      this.onRejectPressed})
      : super();

  @override
  Widget build(BuildContext context) {
    if (postBean != null && (postBean.thumbnail ?? '').isNotEmpty) {
      return normalItem(context);
    } else {
      return simpleItem(context);
    }
  }

  Widget simpleItem(BuildContext context) => Padding(
        padding: const EdgeInsets.only(left: 10, right: 10, top: 8, bottom: 16),
        child: InkWell(
          splashColor: Colors.transparent,
          onTap: () {
            onPressed();
          },
          child: Container(
            decoration: BoxDecoration(
              borderRadius: const BorderRadius.all(Radius.circular(10.0)),
              boxShadow: <BoxShadow>[
                BoxShadow(
                  color: Colors.grey.withOpacity(0.6),
                  offset: const Offset(4, 4),
                  blurRadius: 16,
                ),
              ],
            ),
            child: ClipRRect(
              borderRadius: const BorderRadius.all(Radius.circular(10.0)),
              child: Container(
                color: QuhuiColors.white,
                child: Row(
                  mainAxisAlignment: MainAxisAlignment.center,
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: <Widget>[
                    Expanded(
                      child: Container(
                        child: Padding(
                          padding: const EdgeInsets.only(
                              left: 16, top: 8, bottom: 8),
                          child: Column(
                            mainAxisAlignment: MainAxisAlignment.center,
                            crossAxisAlignment: CrossAxisAlignment.start,
                            children: <Widget>[
                              Row(
                                children: [
                                  Expanded(
                                    child: Text(postBean.title,
                                        textAlign: TextAlign.left,
                                        style: QuhuiConstant.smallTextBold),
                                  ),
                                ],
                              ),
                              Row(
                                children: [
                                  UserInfoWidget(
                                    width: 33,
                                    height: 33,
                                    image: postBean.userLogo,
                                    onPressed: () {
                                      NavigatorUtils.goUserHome(
                                          context, postBean.userId);
                                    },
                                  ),
                                  Text(
                                    postBean.userName,
                                    style: QuhuiConstant.smallSubText,
                                  ),
                                ],
                              ),
                              Row(
                                crossAxisAlignment: CrossAxisAlignment.center,
                                mainAxisAlignment: MainAxisAlignment.start,
                                children: <Widget>[
                                  Expanded(
                                    child: Text(
                                      postBean.summary,
                                      overflow: TextOverflow.ellipsis,
                                      style: QuhuiConstant.minSubText,
                                    ),
                                  ),
                                ],
                              ),
                              Row(
                                children: <Widget>[
                                  InkWell(
                                    onTap: onPassPressed,
                                    child: Container(
                                      width: 50,
                                      height: 50,
                                      alignment: Alignment.center,
                                      child: postBean.status == "DRAFT" ? Icon(
                                        AIcon.paper_plane,
                                      ) : postBean.status == "PUBLISHED" ? Text(
                                        "通过",
                                        style: QuhuiConstant.minTextThemeColor,) : Text(
                                        ""
                                      ),
                                    ),
                                  ),
                                  InkWell(
                                    onTap: onRejectPressed,
                                    child: Container(
                                      width: 50,
                                      height: 50,
                                      alignment: Alignment.center,
                                      child: postBean.status == "DRAFT" ? Icon(
                                        AIcon.sticky_note,
                                      ) : postBean.status == "RECYCLE" ? Text(
                                        "拒绝",
                                        style: QuhuiConstant.smallTextRedBold,) : Text(
                                          ""
                                      ),

                                    ),
                                  ),
                                ],
                              ),
                            ],
                          ),
                        ),
                      ),
                    ),
                  ],
                ),
              ),
            ),
          ),
        ),
      );

  Widget normalItem(BuildContext context) => Padding(
        padding: const EdgeInsets.only(left: 10, right: 10, top: 8, bottom: 16),
        child: InkWell(
          splashColor: Colors.transparent,
          onTap: () {
            onPressed();
          },
          child: Container(
            decoration: BoxDecoration(
              borderRadius: const BorderRadius.all(Radius.circular(10.0)),
              boxShadow: <BoxShadow>[
                BoxShadow(
                  color: Colors.grey.withOpacity(0.6),
                  offset: const Offset(4, 4),
                  blurRadius: 16,
                ),
              ],
            ),
            child: ClipRRect(
              borderRadius: const BorderRadius.all(Radius.circular(10.0)),
              child: Column(
                children: <Widget>[
                  AspectRatio(
                    aspectRatio: 2,
                    child: Stack(
                      fit: StackFit.expand,
                      children: [
                        ExtendedImage.network(
                          postBean.thumbnail,
                          fit: BoxFit.cover,
                        ),
                        Positioned(
                          left: 10,
                          top: 10,
                          child: Row(
                            children: [
                              UserInfoWidget(
                                width: 33,
                                height: 33,
                                image: postBean.userLogo,
                                onPressed: () {
                                  NavigatorUtils.goUserHome(
                                      context, postBean.userId);
                                },
                              ),
                              Text(
                                postBean.userName,
                                style: QuhuiConstant.smallTextWhite,
                              ),
                            ],
                          ),
                        ),
                      ],
                    ),
                  ),
                  Container(
                    color: QuhuiColors.white,
                    child: Row(
                      mainAxisAlignment: MainAxisAlignment.center,
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: <Widget>[
                        Expanded(
                          child: Container(
                            child: Padding(
                              padding: const EdgeInsets.only(
                                  left: 16, top: 8, bottom: 8),
                              child: Column(
                                mainAxisAlignment: MainAxisAlignment.center,
                                crossAxisAlignment: CrossAxisAlignment.start,
                                children: <Widget>[
                                  Row(
                                    children: [
                                      Expanded(
                                        child: Text(postBean.title,
                                            textAlign: TextAlign.left,
                                            style: QuhuiConstant.smallTextBold),
                                      ),
                                      Padding(
                                        padding:
                                            const EdgeInsets.only(right: 8.0),
                                        child: Text(
                                          "浏览 ${postBean.visits}",
                                          style: QuhuiConstant.smallSubText,
                                        ),
                                      )
                                    ],
                                  ),
                                  Row(
                                    crossAxisAlignment:
                                        CrossAxisAlignment.center,
                                    mainAxisAlignment: MainAxisAlignment.start,
                                    children: <Widget>[
                                      Expanded(
                                        child: Text(
                                          postBean.summary,
                                          overflow: TextOverflow.ellipsis,
                                          style: QuhuiConstant.minSubText,
                                        ),
                                      ),
                                    ],
                                  ),
                                  Row(
                                    children: <Widget>[
                                      InkWell(
                                        onTap: onPassPressed,
                                        child: Container(
                                          width: 50,
                                          height: 50,
                                          alignment: Alignment.center,
                                          child: postBean.status == "DRAFT" ? Icon(
                                            AIcon.paper_plane,
                                          ) : postBean.status == "PUBLISHED" ? Text(
                                            "通过",
                                            style: QuhuiConstant.minTextThemeColor,) : Text(
                                              ""
                                          ),
                                        ),
                                      ),
                                      InkWell(
                                        onTap: onRejectPressed,
                                        child: Container(
                                          width: 50,
                                          height: 50,
                                          alignment: Alignment.center,
                                          child: postBean.status == "DRAFT" ? Icon(
                                            AIcon.sticky_note,
                                          ) : postBean.status == "RECYCLE" ? Text(
                                            "拒绝",
                                            style: QuhuiConstant.smallTextRedBold,) : Text(
                                              ""
                                          ),

                                        ),
                                      ),
                                    ],
                                  ),
                                ],
                              ),
                            ),
                          ),
                        ),
                      ],
                    ),
                  ),
                ],
              ),
            ),
          ),
        ),
      );
}
